Skip to main content

All Questions

0votes
1answer
76views

How can I speed up the processing of my nested for loops for a giant 3D numpy array?

I created a very large 3D numpy array called tr_mat. The shape of tr_mat is: tr_mat.shape (1024, 536, 21073) Info on the 3D numpy array: First and before going into the actual code, I would like to ...
Philipp's user avatar
0votes
0answers
38views

Apply a function to every row of a 3-Dimensional numpy array efficiently

I have this function: def sort_row(row): # sums all the pixel values to find a basic pixel "brightness" value summed = np.sum(row[:, :4], axis=1) min_index = np.argmin(summed) ...
SquidBits's user avatar
1vote
2answers
798views

What's the fastest way to generate a 2D grid of values in python?

I need to generate a 2D array in python whose entries are given by a different function above and under the diagonal. I tried the following: x = np.reshape(np.logspace(0.001,10,2**12),(1,4096)) def F(...
John's user avatar
0votes
1answer
141views

Vectorizing a series of operations using NumPy

Following on from my previous question, I am looking for an efficient implementation of a series of operations using NumPy. Problem inputs: X - An (n,2) matrix, where the second column is a ...
sindhuja's user avatar
3votes
1answer
2kviews

Convert bytestring to array of uint8 Python

I was wondering what the fastest way of converting a bytestring to an array of unit8 would be in the following code? I use hashlib for SHA-256 x = hashlib.sha256(str(word).encode("ascii"))....
Mario van Rooij's user avatar
1vote
1answer
146views

Python/Numpy: Vectorizing the combining of row elements with conditions

Is there a way to vectorize the combining of row elements with certain conditions? Conditions: Empty elements get dropped Rows with more than 1 non-empty element get delimited by '\n' Note that a) ...
Craig Nathan's user avatar
-1votes
2answers
1kviews

Is it possible to speed up calculation of very large arrays in numpy?

I have looked around, but could not find an exact answer. I have several matrices of 1200x2000 that I want to save in a way that I can read them later in some sort of loop. When I want to save 100 of ...
Thiago's user avatar
3votes
1answer
866views

Efficient way to calculate standard deviation / volatility of multiple portfolios with numpy multidimensional arrays

I am looking for an efficient/fast method to calculate the volatility/standard deviation of several weithings/portfolios with a multi-dimensional numpy array I have a multidimensional numpy array of ...
RubberDuckDebugging's user avatar
0votes
3answers
677views

How to fill 3D array in numpy with functional values at the same speed as Java?

I tried to model voxels of 3D cylinder with the following code: import math import numpy as np R0 = 500 hz = 1 x = np.arange(-1000, 1000, 1) y = np.arange(-1000, 1000, 1) z = np.arange(-10, 10, 1) ...
Dims's user avatar
  • 51.4k
2votes
0answers
775views

Remove rows of 3D array which are present in a 4D array

I have a 3D numpy array=a containing coordinates of points in space. By transforming this array through matrix operations, I got 4D numpy array, such that for each row of a there is a corresponding 3D ...
Malik's user avatar
4votes
3answers
6kviews

How to assign values to a numpy array as a function of index?

I can only find results that use tuples of coordinates to assign certain values, like this one. I want to assign values to a 2-dimensional array as a function of their coordinates. The simplest case ...
hkchengrex's user avatar
2votes
2answers
1kviews

Why is numpy.take slow on the result of numpy.split when simple indexing is not?

Consider the following code import timeit import numpy as np MyArray = np.empty((10000, 10000, 1)) print((MyArray.size, MyArray.shape, MyArray.dtype, np.isfortran(MyArray))) print(timeit.timeit(...
bers's user avatar
  • 6,013
3votes
2answers
1kviews

Efficiently multiply elements of each row together

Given a ndarray of size (n, 3) with n around 1000, how to multiply together all elements for each row, fast? The (inelegant) second solution below runs in about 0.3 millisecond, can it be improved? # ...
anderstood's user avatar
1vote
1answer
1kviews

Performance bottleneck in Tensordot

While I was trying to understand numpy.tensordot(), I tried out the examples from the documentation and was convinced that we can get exactly same tensordoted result by different permutation of axes ...
kmario23's user avatar
1vote
1answer
238views

Efficiently computing Khatri-Rao like sum (pairwise row sum)

I'm trying to compute Khatri-Rao like sum (i.e. pairwise row sum) and was able to come up with this solution: In [15]: arr1 Out[15]: array([[1, 2, 3], [2, 3, 4], [3, 4, 5]]) In [16]: ...
kmario23's user avatar

153050per page
close